package se.penselnsvag.bookdb.tech.log.formaterr{
	import se.penselnsvag.bookdb.tech.log.LogMessage;
	import se.penselnsvag.bookdb.tech.log.formater.IFormater;
	

/**
* VerboseFormater,
*
* Formater public class for formating LogMessages with all data in LogMessage.
*
* Author:jimmy.lindh@gimlet.se
* Date: 2006-02-23
* Version: 1.0
* History: -
*/


public class HtmlFormater implements IFormater
{
	public function HtmlFormater(){}
	
	private static var instance:HtmlFormater = null;
	
	public static function getInstance() : IFormater
	{
		if(instance==null || instance==undefined)
		{
			instance = new HtmlFormater();	
		}
		return instance;
	}
	
	public function format(logMessage:LogMessage) : String
	{
		if(logMessage is LogMessage)
		{
			var output:String = "<span public class=\"level-" + logMessage.getLogLevelName().toLowerCase() + "\">";
				output += "<span public class=\"date\">" + formatTime(logMessage.getLogTimeStamp()) + "</span>";
				output += "<span public class=\"level\"> - " + logMessage.getLogLevelName() + " - </span>";
				output += logMessage.getLogClassName();
				output += "::" + logMessage.getLogMethodName() + "()";
				output += " - " + logMessage.getLogMessage();
				output += (logMessage.getLogException()==null || logMessage.getLogException()==undefined)? 
						  " " : " : " +logMessage.getLogException().toString();
				output += "</span>";
			
		}
		/*
		else
		{
			return logMessage;
		}
		*/
				return output;
	}
	
	private function formatTime(d:Date):String
	{
		return zeroPad(d.getHours()) + ":" + zeroPad(d.getMinutes()) + ":" + d.getMilliseconds();
	}	
	
	private function zeroPad(n:Number):String 
	{
		if (n<=9)
			return "0"+n;
		else
			return ""+n;
	}
}
}